package maximumPopulation;

import java.util.Arrays;

public class Solution {
    public int maximumPopulation(int[][] logs) {
        // 思路 差分数组
        int m = logs.length;
        int[] cnt = new int[101];
        for (int i = 0; i < logs.length; i++) {
            cnt[logs[i][0]]++;
            cnt[logs[i][1]]--;
        }
        // 求前缀和
        for (int i = 1; i < cnt.length; i++) {
            cnt[i] = cnt[i-1]+cnt[i];
        }
        int max = Arrays.stream(cnt).max().getAsInt();
        for (int i = 0; i < cnt.length; i++) {
            if(cnt[i] == max){
                return i + 1950;
            }
        }
        return 0;
    }
}
